//
//  WBWelcomeView.swift
//  仿写微博
//
//  Created by Apple on 17/7/22.
//  Copyright © 2017年 tuimao. All rights reserved.
//

import UIKit
import SDWebImage
class WBWelcomeView: UIView {

    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
    @IBOutlet weak var iconBottomCons: NSLayoutConstraint!
    
    //xib加载视图
   class func welcomeView() -> WBWelcomeView {
        let nib = UINib.init(nibName: "WBWelcomeView", bundle: nil)
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WBWelcomeView
        v.frame = UIScreen.main.bounds
        return v
    }
    //设置xib的视图
    override func awakeFromNib() {
        
        guard let urlString = WBNetworkManager.shared.useAccount.avatar_large,
            let url = URL(string: urlString) else{
                return
        }
        iconView.setImageWith(url, placeholderImage: UIImage(named: "avatar_default_big"))
        //设置圆角
        //iconView.layer.cornerRadius = iconView.bounds.width * 0.5
        //iconView.layer.masksToBounds = true
    }
    
    //icon的动画
    override func didMoveToWindow() {
        super.didMoveToWindow()
        //原来的时候必须先刷新UI，把不需要动画UI先更新掉，再去更新想要变化的UI,现在不需要这么做了
       // self.layoutIfNeeded()
        iconBottomCons.constant = bounds.height - 200
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            //更新UI
            self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: { 
                self.tipLabel.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
        }
        
    }
    
    
}
